import { BasicColumn, FormSchema } from '/@/components/Table';
import { TenantStatusEnum } from '/@/enums/biz/tenant';
import { query as queryTenant } from '/@/api/devOperation/tenant/tenant';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();
const otherIds = userStore.getTenantId;
export const columns: BasicColumn[] = [
  {
    title: '目标类型',
    dataIndex: 'targetType',
    customRender: ({ record }) => {
      const txts: String = record.echoMap.targetType;
      return <span>{txts}</span>;
    },
  },
  {
    title: '目标任务',
    dataIndex: 'targetType',
  },
  {
    title: '项目描述',
    dataIndex: 'targetDetail',
  },
  {
    title: '百分比',
    dataIndex: 'percentage',
    // customRender: ({ record }) => {
    //   console.log(record, '88888');
    // },
  },
  {
    title: '总分值',
    dataIndex: 'targetSumScore',
  },
  {
    title: '项目分值',
    dataIndex: 'targetScore',
  },
  {
    title: '截止时间',
    dataIndex: 'deadline',
  },
];
// 列表页字段
// const types = [];
// fetchData().then((data) => {
//   // 处理获取到的数据
//   types = data;
// });
// 列表页搜索表单字段
export const searchFormSchema = (): FormSchema[] => {
  return [
    // {
    //   field: 'otherId',
    //   component: 'Select',
    //   label: '请选择二级院部',
    //   colProps: { span: 8 },
    //   componentProps: {
    //     options: [
    //       { value: '520154675945986049', label: '计算机与信息技术学院', key: '1' },
    //       { value: '520154675945986052', label: '商学院', key: '2' },
    //       { value: '520154675945986055', label: '教务处', key: '3' },
    //       { value: '526891104516526724', label: '智能制造技术学院', key: '4' },
    //       { value: '526891104516526727', label: '仲景中医药与健康学院', key: '5' },
    //       { value: '526891104516526732', label: '教育学院', key: '6' },
    //       { value: '526891104516526749', label: '建筑与艺术设计学院', key: '7' },
    //       { value: '526891104516526752', label: '体育学院', key: '8' },
    //       { value: '526891104516526755', label: '中专部', key: '9' },
    //       { value: '526891104516526758', label: '公共教学部', key: '10' },
    //       { value: '526891104516526761', label: '马克思主义学院', key: '11' },
    //       { value: '526891104516526764', label: '继续教育学院', key: '12' },
    //       { value: '526891104516526767', label: '党群工作部', key: '13' },
    //       { value: '526891104516526770', label: '党政办公室', key: '14' },
    //       { value: '526891104516526774', label: '发展规划处（创新创业学院）', key: '15' },
    //       { value: '526891104516526777', label: '人力资源部', key: '16' },
    //       { value: '526891104516526780', label: '科技外事处', key: '17' },
    //       { value: '526891104516526783', label: '学生工作处', key: '18' },
    //       { value: '526891104516526786', label: '法务监督部', key: '19' },
    //       { value: '526891104516526789', label: '招生工作办公室', key: '20' },
    //       {
    //         value: '526891104516526796',
    //         label: '大学生实习实训与就业指导中心（校地合作处）',
    //         key: '21',
    //       },
    //       { value: '526891104516526799', label: '财务处', key: '22' },
    //       { value: '526891104516526802', label: '基建处', key: '23' },
    //       { value: '526891104516526805', label: '保卫处', key: '24' },
    //       { value: '526891104516526808', label: '后勤管理处', key: '25' },
    //       { value: '526891104516526813', label: '心理健康教育中心', key: '26' },
    //       { value: '526891104516526823', label: '图书馆', key: '27' },
    //       { value: '526891104516526831', label: '后勤服务集团直属党支部', key: '28' },
    //     ],
    //   },
    // },
    {
      field: 'otherId',
      label: '请选择二级院部',
      component: 'ApiSelect',
      componentProps: ({ tableAction }) => {
        return {
          api: queryTenant,
          labelField: 'name',
          valueField: 'id',
          params: {
            status: TenantStatusEnum.NORMAL,
          },
          showSearch: true,
          filterOption: (input: string, option: any) => {
            return option.label.toUpperCase().indexOf(input.toUpperCase()) >= 0;
          },
          onChange: (value) => {
            const { reload } = tableAction;
            reload({ searchInfo: { otherId: value } });
          },
        };
      },
      ifShow: otherIds == '1',
      colProps: { span: 8 },
    },
    {
      label: '请选择年份',
      field: 'targetYear',
      component: 'Select',
      colProps: { span: 8 },
      componentProps: {
        options: Array.from({ length: 21 }, (_, index) => ({
          label: 2023 + index + '',
          value: 2023 + index,
        })),
      },
    },
  ];
};

export const Updatecolumns: BasicColumn[] = [
  {
    title: '项目类型',
    dataIndex: 'targetType',
    customRender: ({ record }) => {
      const txts: String = record.echoMap.targetType;
      if (record.list != undefined) {
        return <span style={{ textAlign: 'center' }}>{txts}</span>;
      } else {
        const indexNum = record.indexNum;
        const displayText = ` ${indexNum}`;
        return <p>{displayText}</p>;
      }
    },
    width: 140,
  },
  {
    title: '完成情况',
    dataIndex: 'targetType',
    width: 210,
    customRender: ({ record }) => {
      const sumScore = record.sumScore;
      const percentage = record.percentage;
      const targetState = record.targetState;
      const score = record.score;
      if (typeof sumScore !== 'undefined') {
        return (
          <span>
            分数（占比）:{sumScore}/{percentage}
          </span>
        );
      } else {
        return (
          <span>
            分数（状态）:{score}---{targetState}
          </span>
        );
      }
    },
  },
  {
    title: '项目描述',
    dataIndex: 'targetDetail',
    customRender: ({ record }) => {
      const targetDetail = record.targetDetail;
      return <span style={{ textAlign: 'left' }}>{targetDetail}</span>;
    },
    // width: 300,
  },
  {
    title: '项目分值',
    dataIndex: 'targetScore',
    width: 100,
    customRender: ({ record }) => {
      const targetScore = record.targetScore;
      const targetSumScore = record.targetSumScore;
      if (typeof targetSumScore !== 'undefined') {
        return <span>{targetSumScore}</span>;
      } else {
        return <span>{targetScore}</span>;
      }

      // return <span>{txts}</span>;
    },
  },
  {
    title: '截止时间',
    dataIndex: 'deadline',
    width: 100,
  },
];
